//
//  LDSViewModel.m
//  LDSMVVMBase
//
//  Created by kai_leedarson on 2017/9/30.
//  Copyright © 2017年 maple_leedarson. All rights reserved.
//

#import "LDSViewModel.h"
#import "UIView+LDSExtensions.h"

@implementation LDSViewModel
- (LDSBaseView *)view {
    if (_viewClass && [_viewClass isSubclassOfClass:[LDSBaseView class]]) {
        LDSBaseView *view = nil;
        if (_xib) {
            view = (LDSBaseView *)[_viewClass dequeueReusableFromXib];
            view.frame = _frame;
        } else {
            view = (LDSBaseView *)[_viewClass dequeueReusableWithFrame:_frame];
        }
        return view;
    }
    return nil;
}

+ (LDSViewModel *)modelViewWithClass:(Class)vClass frame:(CGRect)frame model:(id)model
{
    LDSViewModel *vModel = [[LDSViewModel alloc] init];
    if (vClass) {
        [vModel setViewClass:vClass];
        [vModel setFrame:frame];
        [vModel setModel:model];
    }
    return vModel;
}

+ (LDSViewModel *)modelViewWithClass:(Class)vClass model:(id)model {
    return [LDSViewModel modelViewWithClass:vClass frame:CGRectZero model:model];
}
@end
